<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"  	
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:georss="http://www.georss.org/georss"
  xmlns:aml="http://markup-languages.googlecode.com/ns/aml"
  xmlns:dc="http://purl.org/dc/elements/1.1/">
  <xsl:param name="sortOrder">descending</xsl:param>
  <xsl:variable name="monthNames" 
    select="'|Jan|Feb|Mar|Apr|May|Jun|Jul|
    Aug|Sep|Oct|Nov|Dec'"/>
  <xsl:output method="xml" indent="yes" />

  <xsl:template match="aml:aggregated" >
  <rss version="2.0">
    <channel>
		<title>From the Editors</title>
	    <link>http://computingnow.computer.org/</link>
	    <description>Collected Blogs of the IEEE Computing Now Editorial Board.</description>
	    <xsl:for-each select="//aml:entry">
	      <xsl:sort select="substring(substring-after(substring-after(substring-after(./aml:pubDate, ' '), ' '), ' '), 1, 4)" 
	        order='{$sortOrder}'/>
	      <xsl:sort 
	        select="string-length(substring-before($monthNames,substring(substring-after(substring-after(./aml:pubDate, ' '), ' '), 1, 3)))"
	        order="{$sortOrder}"/>
	      <xsl:sort select="substring(substring-after(./aml:pubDate, ' '), 1, 2)"
	        data-type="number" 
	        order="{$sortOrder}"/>
	      <xsl:sort select="substring(substring-after(substring-after(substring-after(substring-after(./aml:pubDate/text(), ' '), ' '), ' '), ' '), 1, 8)"
	        data-type="text" 
	        order="{$sortOrder}"/>
	      
	      <xsl:element name="item">
	         <xsl:element name="title">
	           <xsl:value-of select="aml:title"/>
	         </xsl:element>
	         <xsl:element name="dc:creator">
	           <xsl:value-of select="aml:author"/>
	         </xsl:element>
	        <xsl:element name="pubDate">
	          <xsl:value-of select="aml:pubDate"/>
	        </xsl:element>
	         <xsl:element name="link">
	           <xsl:value-of select="aml:link"/>
	         </xsl:element>
	         <xsl:apply-templates select="aml:category"/>
	         <xsl:element name="description">
	           <xsl:value-of select="aml:description"/>
	         </xsl:element>
	      	<xsl:element name="guid">
	      		<xsl:copy-of select="aml:guid/@isPermaLink"/>
	      		<xsl:value-of select="aml:guid"/>
	      	</xsl:element>
	      </xsl:element>
	    </xsl:for-each>
    </channel>
  </rss>
  
  </xsl:template>
	
	<xsl:template match="aml:guid">
		<guid><xsl:copy></xsl:copy></guid>
	</xsl:template>
	
  <xsl:template match="aml:category">
    <xsl:element name="category">
      <xsl:value-of select="."/>
    </xsl:element>
  </xsl:template>
</xsl:stylesheet>
